package prh25.biblioteca.entity.dao.hibernate;

import java.util.List;
import java.sql.Timestamp;



import org.hibernate.criterion.Restrictions;

import prh25.biblioteca.entity.Documento;
import prh25.biblioteca.entity.dao.DocumentoDAO;

/**
 * <p>Hibernate DAO layer for Documentos</p>
 * <p></p>
 *
 * @author Wilson
 * @see http://code.google.com/p/prh-doc/
 */
public class DocumentoHibernateDAO extends
		AbstractHibernateDAO<Documento, Integer> implements
		DocumentoDAO {

	/**
	 * Find Documento by version
	 */
	public List<Documento> findByVersion(Integer version) {
		return findByCriteria(Restrictions.eq("version", version));
	}
	
	/**
	 * Find Documento by entityUid
	 */
	public List<Documento> findByEntityUid(String entityUid) {
		return findByCriteria(Restrictions.eq("uid", entityUid));
	}
	
	/**
	 * Find Documento by ativo
	 */
	public List<Documento> findByAtivo(Boolean ativo) {
		return findByCriteria(Restrictions.eq("ativo", ativo));
	}
	
	/**
	 * Find Documento by title
	 */
	public List<Documento> findByTitle(String title) {
		return findByCriteria(Restrictions.eq("title", title));
	}
	
	/**
	 * Find Documento by creator
	 */
	public List<Documento> findByCreator(String creator) {
		return findByCriteria(Restrictions.eq("creator", creator));
	}
	
	/**
	 * Find Documento by subject
	 */
	public List<Documento> findBySubject(String subject) {
		return findByCriteria(Restrictions.eq("subject", subject));
	}
	
	/**
	 * Find Documento by description
	 */
	public List<Documento> findByDescription(String description) {
		return findByCriteria(Restrictions.eq("description", description));
	}
	
	/**
	 * Find Documento by publisher
	 */
	public List<Documento> findByPublisher(String publisher) {
		return findByCriteria(Restrictions.eq("publisher", publisher));
	}
	
	/**
	 * Find Documento by contributor
	 */
	public List<Documento> findByContributor(String contributor) {
		return findByCriteria(Restrictions.eq("contributor", contributor));
	}
	
	/**
	 * Find Documento by date
	 */
	public List<Documento> findByDate(Timestamp date) {
		return findByCriteria(Restrictions.eq("date", date));
	}
	
	/**
	 * Find Documento by type
	 */
	public List<Documento> findByType(String type) {
		return findByCriteria(Restrictions.eq("type", type));
	}
	
	/**
	 * Find Documento by format
	 */
	public List<Documento> findByFormat(String format) {
		return findByCriteria(Restrictions.eq("format", format));
	}
	
	/**
	 * Find Documento by identifier
	 */
	public List<Documento> findByIdentifier(String identifier) {
		return findByCriteria(Restrictions.eq("identifier", identifier));
	}
	
	/**
	 * Find Documento by source
	 */
	public List<Documento> findBySource(String source) {
		return findByCriteria(Restrictions.eq("source", source));
	}
	
	/**
	 * Find Documento by language
	 */
	public List<Documento> findByLanguage(String language) {
		return findByCriteria(Restrictions.eq("language", language));
	}
	
	/**
	 * Find Documento by relation
	 */
	public List<Documento> findByRelation(String relation) {
		return findByCriteria(Restrictions.eq("relation", relation));
	}
	
	/**
	 * Find Documento by coverage
	 */
	public List<Documento> findByCoverage(String coverage) {
		return findByCriteria(Restrictions.eq("coverage", coverage));
	}
	
	/**
	 * Find Documento by rights
	 */
	public List<Documento> findByRights(String rights) {
		return findByCriteria(Restrictions.eq("rights", rights));
	}
	
	/**
	 * Find Documento by arquivoId
	 */
	@SuppressWarnings("unchecked")
	public List<Documento> findByArquivoId(Integer arquivoId) {
		return findByCriteria(Restrictions.eq("arquivo.id", arquivoId));
	}
	
	/**
	 * Find Documento by revisorId
	 */
	@SuppressWarnings("unchecked")
	public List<Documento> findByRevisorId(Integer revisorId) {
		return findByCriteria(Restrictions.eq("revisor.id", revisorId));
	}
	
	/**
	 * Find Documento by usuarioId
	 */
	@SuppressWarnings("unchecked")
	public List<Documento> findByUsuarioId(Integer usuarioId) {
		return findByCriteria(Restrictions.eq("usuario.id", usuarioId));
	}

	
	@Override
	public List<Documento> findByDescriptionLike(String description, Boolean ativo) {
		return findByCriteria(Restrictions.like("description", description).ignoreCase(),
				                Restrictions.eq("ativo", ativo));
	}

	@Override
	public List<Documento> findByTitleLike(String title, Boolean ativo) {
		return findByCriteria(Restrictions.like("title", title).ignoreCase(),
				                Restrictions.eq("ativo", ativo));
	}

	@Override
	public List<Documento> findByUsuarioId(Integer usuarioId, Boolean ativo) {
		return findByCriteria(Restrictions.eq("usuario.id", usuarioId),
				                Restrictions.eq("ativo", ativo));
	}

	@Override
	public List<Documento> findByCreatorLike(String creator, Boolean ativo) {
		return findByCriteria(Restrictions.like("creator", creator).ignoreCase(),
				                 Restrictions.eq("ativo", ativo));
	}
	

}
